package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iwhalecloud.bss.kite.client.api.scene.operate.IOperateSceneCommonService;
import com.iwhalecloud.bss.kite.client.api.scene.operate.IOperateSceneProdInstService;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.SymbolConsts;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.IInstallationAddressService;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.IUnicomRegionService;
import com.iwhalecloud.bss.kite.cucc.client.dto.attr.AreaCode;
import com.iwhalecloud.bss.kite.cucc.client.dto.attr.AreaInquiry;
import com.iwhalecloud.bss.kite.cucc.client.dto.attr.BuildingInquiryDTO;
import com.iwhalecloud.bss.kite.cucc.client.vo.attr.BuildingInfo;
import com.iwhalecloud.bss.kite.cucc.client.vo.attr.BuildingInfoVo;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.BackfillInstallAddressAttrHandler;
import com.iwhalecloud.bss.kite.cucc.service.pos.handler.CuccPosServiceUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import com.ztesoft.zsmart.core.exception.BaseAppException;
import com.ztesoft.zsmart.core.util.JsonUtil;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Classname BackfillInstallAddressAttrLinkHandler
 * @Description 装机地址弹出框选择地址确认后，需要额外回填  标准地址ID、标准地址名称、楼宇编码、楼宇名称
 * @Author zhang.song
 * @Date 2021-03-03 17:16
 */
@Service
@AttrHandler(BackfillInstallAddressAttrHandler.class)
public class BackfillInstallAddressAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Resource
    private OperateInstAttrService operateInstAttrService;

    @Resource
    private IUnicomRegionService unicomRegionService;

    @Resource
    private IInstallationAddressService installationAddressService;

    @Autowired
    private IOperateSceneCommonService operateSceneCommonService;

    @Resource
    private IQuerySceneInstService querySceneInstService;

    @Resource
    private IOperateSceneProdInstService operateSceneProdInstService;

    private static String typeTag_1 = "1";

    private static String typeTag_2 = "2";

    private static String typeTag_3 = "3";

    private static String EDIT_TYPE_SF = "SF";
    private static String EDIT_TYPE_ST = "ST";

    private static String source_result_attr_id ="20220224775";

    private static String YJJD = "10003509"; // 云聚节点--云联网专线接入产品-新版 的prodID

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 互联网专线 IP地址备案信息模块中 单位详细地址  与装机地址属性联动
        if (Objects.isNull(attr)) {
            return;
        }
        IOperateSceneInstService operateSceneInstService = SpringUtil.getBean(IOperateSceneInstService.class);
        KiteAttr  unitDetailAddressAttr = querySceneInstService.getCommonAttr(data.getSceneInstId(),"2_0000211");
        if (Objects.nonNull(unitDetailAddressAttr) && KiteStringUtils.isNotEmpty(attr.getValueDesc())) {
            unitDetailAddressAttr.setValue(attr.getValueDesc());
            unitDetailAddressAttr.setValueDesc(attr.getValueDesc());
            operateSceneCommonService.setCommonAttr(data.getSceneInstId(), unitDetailAddressAttr);
        }
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(data.getSceneInstId());
        KiteOfferInst offerInst = querySceneInstService.getOfferInst(data.getCustId(), sceneInst.getRootInstId());
        String value = attr.getValue();
        if (KiteStringUtils.isEmpty(value) || !value.startsWith("{") || !value.endsWith("}")) {
            return;
        }
        Map<String, Object> dataMap = null;
        try {
            dataMap = JsonUtil.json2Object(value, Map.class);
        } catch (BaseAppException e) {
        }
        if(dataMap == null || dataMap.size() == 0) {
            return;
        }
        String segmType = MapUtils.getString(dataMap, "segmType");
        if(KiteStringUtils.isNotEmpty(segmType)&&Integer.parseInt(segmType)>7){
            attr.setIsEdit("ST");
        }
        // 标准地址ID、楼宇编码、楼宇名称、省编码，省份楼宇编码
        String fieldName = attr.getFieldName();
        String addressIdFileName = null;
        String buildingCodeFileName = null;
        String buildingNameFileName = null;
        String provinceFileName = null;
        String provinceFileId = null;
        boolean isDia = false;
        if("2_0000211".equals(fieldName)) {
            // A端
            provinceFileName = "2_0000220";
            provinceFileId="210008053";
            // 互联网专线，编码有区别
            if (KiteStringUtils.equals(ProdCateUtil.getSingleCateId(ProdCateUtil.DIA_CODE), CuccPosServiceUtils.getCateId(data.getSceneInstId(), data.getCustId()))) {
                addressIdFileName = "200002617";
                buildingCodeFileName = "200001951";
                buildingNameFileName = "200002737";
                provinceFileId="210008002";
                isDia = true;
            } else {
                addressIdFileName = "200002618";
                buildingCodeFileName = "210003991";
                buildingNameFileName = "200002982";
                if(KiteStringUtils.equalsAny(offerInst.getSpecId(), "50041903", "50041904")){
                    // 河北MV,A端标准地址id编码为200002618;
                    addressIdFileName = "200002618";
                }else if(KiteStringUtils.equals(inst.getSpecId(),"10003666") || KiteStringUtils.equals(inst.getSpecId(),YJJD)){
                    // 地区MV,云聚节点的标准地址id编码为200002617;
                    addressIdFileName = "200002617";
                }
            }
        } else if("2_0000117".equals(fieldName)) {
            // Z端
            provinceFileId="210008054";
            addressIdFileName = "200002619";
            buildingCodeFileName = "210003992";
            buildingNameFileName = "200002985";
            provinceFileName = "2_0000107";
        }
        // 省分楼宇编码
        String provincebuildingId = MapUtils.getString(dataMap, "provincebuildingId");
        KiteAttr provinceFileIdAttr = inst.getAttr(provinceFileId);
        // 标准地址id
        String addressId = MapUtils.getString(dataMap, "segmId");
        KiteAttr addressAttr = inst.getAttr(addressIdFileName);
        String addressValue = Objects.nonNull(addressAttr)?addressAttr.getValue():"";
        //省份标准地址编码
        String addressFrom = MapUtils.getString(dataMap, "addressFrom");
        KiteAttr addressAttrFrom = inst.getAttr("210008066");

        // 是否手动编辑地址描述信息
        boolean editAddressDetailFlag = (KiteStringUtils.equals(addressId, addressValue) && !KiteStringUtils.equals(addressId, ""))
            || (KiteStringUtils.equals(addressId, "") && !KiteStringUtils.equals("", MapUtils.getString(dataMap, "segmName")));
        if (Objects.nonNull(provinceFileIdAttr) && !editAddressDetailFlag) {
            provinceFileIdAttr.setValue(provincebuildingId);
            provinceFileIdAttr.setValueDesc(provincebuildingId);
            operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), provinceFileIdAttr);
        }
        if (Objects.nonNull(addressAttr) && !editAddressDetailFlag) {
            addressAttr.setValue(addressId);
            addressAttr.setValueDesc(addressId);
            operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), addressAttr);
        }

        if (Objects.nonNull(addressAttrFrom) && !editAddressDetailFlag) {
            addressAttrFrom.setValue(addressFrom);
            addressAttrFrom.setValueDesc(addressFrom);
            operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), addressAttrFrom);
        }
        // 如果楼宇信息为装机地址关联带出，则切换装机地址清空
        KiteAttr buildingCodeAttr = inst.getAttr(buildingCodeFileName);
        if (Objects.nonNull(buildingCodeAttr) && KiteStringUtils.isEqual(buildingCodeAttr.getIsEdit(), KeyConsts.IFTRUE_F) && !editAddressDetailFlag) {
            buildingCodeAttr.setValue(null);
            buildingCodeAttr.setValueDesc(null);
            if(isDia){
               // buildingCodeAttr.setIsEdit(KeyConsts.IFTRUE_T);
            }else {
                buildingCodeAttr.setIsEdit(KeyConsts.IFTRUE_F);
            }
        }
        KiteAttr buildingNameAttr = inst.getAttr(buildingNameFileName);
        if (Objects.nonNull(buildingNameAttr) && KiteStringUtils.isEqual(buildingNameAttr.getIsEdit(), KeyConsts.IFTRUE_F) && !editAddressDetailFlag) {
            buildingNameAttr.setValue(null);
            buildingNameAttr.setValueDesc(null);
            // buildingNameAttr.setIsEdit(KeyConsts.IFTRUE_T);
        }
        // 地图辅助查询选择楼宇后会返回楼宇名称和楼宇编码（必返回）
        String buildingId = MapUtils.getString(dataMap, "buildingId");
        String buildingName = MapUtils.getString(dataMap, "buildingName");
        if (KiteStringUtils.isNotEmpty(buildingId)) {
            buildingCodeAttr.setValue(buildingId);
            buildingCodeAttr.setValueDesc(buildingId);
            buildingCodeAttr.setIsEdit(KeyConsts.IFTRUE_F);
        }
        if (KiteStringUtils.isNotEmpty(buildingName)) {
            buildingNameAttr.setValue(buildingName);
            buildingNameAttr.setValueDesc(buildingName);
            buildingNameAttr.setIsEdit(KeyConsts.IFTRUE_F);
        }

        if(KiteStringUtils.isNotEmpty(addressId)) {
            KiteAttr provinceAttr = inst.getAttr(provinceFileName);
            if(Objects.nonNull(provinceAttr) && KiteStringUtils.isNotEmpty(provinceAttr.getValue())) {
                // 根据标准地址id、省id查楼宇信息
                BuildingInfo buildingInfo = this.queryBuilding(addressId, provinceAttr.getValue());
                if(Objects.nonNull(buildingInfo)) {
                    // 赋值 楼宇编码
                    String buildingNoId = buildingInfo.getBuildingIdGroup();
                    if (Objects.nonNull(buildingCodeAttr) && KiteStringUtils.isNotEmpty(buildingNoId)) {
                        buildingCodeAttr.setValue(buildingNoId);
                        buildingCodeAttr.setValueDesc(buildingNoId);
                        buildingCodeAttr.setIsEdit(KeyConsts.IFTRUE_F);
                    }
                    // 赋值 楼宇名称
                    String buildingNoName = buildingInfo.getBuildingName();
                    if (Objects.nonNull(buildingNameAttr) && KiteStringUtils.isNotEmpty(buildingNoName)) {
                        buildingNameAttr.setValue(buildingNoName);
                        buildingNameAttr.setValueDesc(buildingNoName);
                        buildingNameAttr.setIsEdit(KeyConsts.IFTRUE_F);
                    }
                }
            }
        }
        String provinceCode = MapUtils.getString(dataMap, "provinceCode");
        String eparchyCode = MapUtils.getString(dataMap, "eparchyCode");
        String cityCode = MapUtils.getString(dataMap, "cityCode");
        JSONObject valueDescJson = JSON.parseObject(attr.getValueDesc());
        //String provinceCodeDesc = valueDescJson.getString("provinceCode");
        //String eparchyCodeDesc = valueDescJson.getString("eparchyCode");
        //String cityCodeDesc = valueDescJson.getString("cityCode");
        if(!KiteStringUtils.isAnyEmpty(provinceCode,eparchyCode,cityCode)){
            String zjAttrName = "";
            if(KiteStringUtils.equals(fieldName,"2_0000211")){
                zjAttrName = "2_0000209";
                if("10003509".equals(inst.getSpecId())){
                    // 云联网专线接入产品-新版
                    zjAttrName = "2_0000208";
                }
            }else if(KiteStringUtils.equals(fieldName,"2_0000117")){
                zjAttrName = "2_0000105";
            }
            if(KiteStringUtils.isNotEmpty(zjAttrName)){
                String zjAttrValue = KiteStringUtils.concatWithSymbol(provinceCode,eparchyCode, SymbolConsts.COMMA);
                zjAttrValue = KiteStringUtils.concatWithSymbol(zjAttrValue,cityCode, SymbolConsts.COMMA);
                //String zjAttrValueDesc = KiteStringUtils.concatWithSymbol(provinceCodeDesc,eparchyCodeDesc, SymbolConsts.COMMA);
                //zjAttrValueDesc = KiteStringUtils.concatWithSymbol(zjAttrValueDesc,cityCodeDesc, SymbolConsts.COMMA);
                operateInstAttrService.setAttrValue(inst, zjAttrName, zjAttrValue, data.getSceneInstId(), null);
                operateSceneProdInstService.updateProdInstAttr(data.getSceneInstId(), inst.getInstId(), zjAttrName , zjAttrValue, null, data.getCustId(), ContextUtil.getUserId().toString(), null);
            }
        }
        if("10003509".equals(inst.getSpecId())){
            // 云联网专线接入产品-新版

            KiteAttr addressDetailAttr = inst.getAttr("2_0000212");
            StringBuffer addressDetail = new StringBuffer();
            addressDetail.append(MapUtils.getString(dataMap, "segmName"));
            if(KiteStringUtils.isNotEmpty(addressDetailAttr.getValue())){
                addressDetail.append("-");
                addressDetail.append(addressDetailAttr.getValue());
            }
            operateInstAttrService.setAttrValue(inst, "200001752", addressDetail.toString(), data.getSceneInstId(), null);
        }
        String typeTag = KiteMapUtils.getString(dataMap, "typeTag");

        if (KiteStringUtils.equalsAny(typeTag, typeTag_1, typeTag_2)) {
            attr.setIsEdit(EDIT_TYPE_SF);
        }
        else if (KiteStringUtils.equals(typeTag, typeTag_3)) {
            operateSceneInstService.putExtParameter(data.getSceneInstId(), attr.getGroupId() + "_" + attr.getFieldName(), typeTag);
            attr.setIsNull(KeyConsts.IFTRUE_F);
            attr.setIsEdit(EDIT_TYPE_ST);
        }
        attr.setIsNull(EDIT_TYPE_SF);
        operateInstAttrService.setAttrValue(inst, attr.getFieldName(), MapUtils.getString(dataMap, "segmName"), data.getSceneInstId(), null);


        linkBackfill(dataMap,inst,data, attr);
        // 回填查询条件
        dealCondition(dataMap, inst, data, attr);
    }

    /**
     * 标准地址查询条件回填
     * @param dataMap
     * @param inst
     * @param data
     */
    private void dealCondition(Map<String, Object> dataMap, KiteInst inst, AttrData data, KiteAttr attr) {
        Map<String, Object> conditions = KiteMapUtils.getMap(dataMap, "conditions");
        if (Objects.nonNull(conditions) && !conditions.isEmpty()) {
            conditions.entrySet().forEach(condition -> {
                operateInstAttrService.setAttrValue(inst, condition.getKey(), String.valueOf(condition.getValue()), data.getSceneInstId(), null);
            });
        }
        // 产商品增加标识区分：标准地址、百度楼宇、经纬度，销售传给订单中心，页面不展示非必填
        if (dataMap.containsKey("typeTag")) {
            String typeTag = KiteMapUtils.getString(dataMap, "typeTag");
            operateInstAttrService.setAttrValue(inst, "210008230", typeTag, data.getSceneInstId(), null);
        }
        // 天津资源核查结果返回送给订单中心
        if (dataMap.containsKey("resPrejudgeResult")) {
            String resPrejudgeResult = KiteMapUtils.getString(dataMap, "resPrejudgeResult");
            String [] result = resPrejudgeResult.split("——");
            // 把资源审核的结果回填到对应的属性上去。
            KiteAttr kiteAttr = inst.listAttrs().stream().filter(Attr -> KiteStringUtils.equals(Attr.getGroupId(), attr.getGroupId()) && KiteStringUtils.equals(Attr.getAttrId(), source_result_attr_id)).findFirst().orElse(null);
            if (!ObjectUtils.isEmpty(kiteAttr) && result.length>1){
                kiteAttr.setValue(result[0]);
                kiteAttr.setValueDesc(result[1]);
            }

        }
    }

    /**
     * 回填资源预判返回的属性值
     */
    private void linkBackfill (Map<String, Object> dataMap,KiteInst inst, AttrData data, KiteAttr attr){
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(data.getSceneInstId());
        String provinceCode = sceneInst.getProvinceNbr();
        String cateId =  CuccPosServiceUtils.getCateId(data.getSceneInstId(),data.getCustId());
        String serviceOfferId = data.getServiceOfferId();
        if (LocalKeyConsts.PROVINCE_ZHEJIANG.equals(provinceCode) && "2004029".equals(cateId) && KiteStringUtils.equalsAny(serviceOfferId,"1","2826","1014")){
            Map<String, Object> resPrejudge = KiteMapUtils.getValue(dataMap,"resPrejudge");
            if(Objects.nonNull(resPrejudge) && resPrejudge.size()>0){
                //资源预判结果
                String prejuctResult = KiteMapUtils.getValue(resPrejudge, "respCode");
                queryDcPublic(inst,data,"200002663",prejuctResult);

                //局向编码 局向名称
                List<Map<String, Object>> exchList = KiteMapUtils.getValue(resPrejudge, "exchList");
                if (KiteListUtils.isNotEmpty(exchList) && exchList.size()>0){
                    operateInstAttrService.setAttrValue(inst,"200003332",KiteMapUtils.getValue(exchList.get(0),"exchCode"),data.getSceneInstId(),null);
                    operateInstAttrService.setAttrValue(inst,"200003333",KiteMapUtils.getValue(exchList.get(0),"exchName"),data.getSceneInstId(),null);
                }
                //接入方式
                String accessType = KiteMapUtils.getValue(resPrejudge, "accessType");
                if (KiteStringUtils.isNotEmpty(accessType)){
                    queryDcPublic(inst,data, "10000192",accessType);
                }
                //其他属性
                List<Map<String ,Object>> addressAttrInfoL = KiteMapUtils.getValue(resPrejudge,"addressAttrInfo");
                if (KiteListUtils.isNotEmpty(addressAttrInfoL) && addressAttrInfoL.size()>0){
                    addressAttrInfoL.forEach(addressAttrInfo->{
                        String fieldN = KiteMapUtils.getValue(addressAttrInfo,"attrCode");
                        String value = KiteMapUtils.getValue(addressAttrInfo,"attrValue");
                        queryDcPublic(inst, data, fieldN, value);
                    });
                }
            }else {
                //资源预判结果
                queryDcPublic(inst,data,"200002663","1111");
                //其他属性清空
                List<DcPublic> dcPublics = DcPublicCache.getByPkey("20220117","prejudge_field_name");
                if (KiteListUtils.isNotEmpty(dcPublics)){
                    dcPublics.forEach(dcPub->{
                        KiteAttr kiteAttr = querySceneInstService.getInstAttr(data.getCustId(),inst.getInstType(),inst.getInstId(),dcPub.getPcode());
                        if (Objects.nonNull(kiteAttr) && KiteStringUtils.isNotEmpty(kiteAttr.getValue())){
                            operateInstAttrService.setAttrValue(inst,kiteAttr.getFieldName(),"",data.getSceneInstId(),null);
                        }
                    });
                }
            }
        }
        // 省份标准地址编码
        String addressFrom = KiteMapUtils.getValue(dataMap,"addressFrom");

        // 每个产品的field_anme都不一样。
        KiteAttr kAttr = inst.listAttrs().stream().filter(kiteAttr -> KiteStringUtils.equals(kiteAttr.getGroupId(), attr.getGroupId()) && KiteStringUtils.contains(kiteAttr.getCname(),"省份标准地址编码")).findFirst().orElse(null);
        if (!ObjectUtils.isEmpty(kAttr)) {
            operateInstAttrService.setAttrValue(inst,kAttr.getFieldName(), addressFrom, data.getSceneInstId(),null);
        }
    }

    /**
     * 从dcPublic表查询映射的产商品属性编码、属性值编码
     */
    private void queryDcPublic(KiteInst inst, AttrData data, String fieldN, String value){
        String fieldName = DcPublicCache.getCodea(fieldN,value);
        if (KiteStringUtils.isNotEmpty(fieldName)){
            //配置了映射关系
            KiteAttr kiteAttr = inst.getAttr(fieldName);
            if (Objects.nonNull(kiteAttr)){
                if ("98A".equals(kiteAttr.getAttrValueTypeId())){
                    //属性值类型为98A 取映射的值
                    String attrValue = DcPublicCache.getPCode(fieldN,value);
                    operateInstAttrService.setAttrValue(inst,fieldName,attrValue,data.getSceneInstId(),null);
                }else {
                    //属性值类型为98C 直接设值
                    operateInstAttrService.setAttrValue(inst,fieldName,value,data.getSceneInstId(),null);
                }
            }
        }else {
            //未配置映射关系，直接设值
            KiteAttr kiteAttr = inst.getAttr(fieldN);
            if (Objects.nonNull(kiteAttr)){
                operateInstAttrService.setAttrValue(inst,fieldN,value,data.getSceneInstId(),null);
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }

    // 根据标准地址id查询楼宇编码、名称
    private BuildingInfo queryBuilding(String addressId, String provinceId) {
        // 区域编码转换
        AreaInquiry areaInquiry = new AreaInquiry();
        areaInquiry.setGradeId(1);
        areaInquiry.setCode(provinceId);
        AreaCode areaCode = unicomRegionService.regionTransform(areaInquiry);

        if(areaCode != null && KiteStringUtils.equals(areaCode.getCode(), "00000")) {
            if (KiteStringUtils.isNotEmpty(areaCode.getProvinceCode())) {
                // 查询楼宇信息
                BuildingInquiryDTO buildingInquiryDTO = new BuildingInquiryDTO();
                buildingInquiryDTO.setAddressId(addressId);
                buildingInquiryDTO.setProvinceId(areaCode.getProvinceCode());
                BuildingInfoVo buildingInfoVo = installationAddressService.queryBuilding(buildingInquiryDTO);
                if(buildingInfoVo != null && KiteStringUtils.equals(buildingInfoVo.getCode(), "00000")) {
                    List<BuildingInfo> buildingInfoList = buildingInfoVo.getBuildingInfoList();
                    if(buildingInfoList != null && buildingInfoList.size() > 0) {
                        return buildingInfoList.get(0);
                    }
                }
            }
        }
        return null;
    }
}
